/**
 * @date: 2025/3/17
 * @author: 小红
 * @fileName: config
 * @Description: 配置
 */

import type { LocalMicroAppConfig, MicroAppConfig } from './index'
import { useAuthStore } from '@/stores/modules/auth'
import { useAppStore } from '@/stores/modules/app'
import { useUserStore } from '@/stores/modules/user'
import plugins from '@/micro/plugins'
import lifecycles from '@/micro/lifecycles'
import { toRaw } from 'vue'

/**
 * 获取本地配置
 */
export function getLocalConfig(): LocalMicroAppConfig {
  const authStore = useAuthStore()
  const appStore = useAppStore()
  const userStore = useUserStore()

  return {
    alive: true, // 是否保活
    // exec: true, //默认执行
    sync: true, // 是否同步
    props: {
      app: {
        locale: appStore.locale,
      },
      auth: {
        accessToken: authStore.accessToken,
        refreshToken: authStore.refreshToken,
      },
      userInfo: toRaw(userStore.userInfo),
    },
    plugins,
    ...lifecycles,
  }
}

/**
 * 微服务配置开发环境
 */
export const DevMicroAppConfig: MicroAppConfig[] = [
  {
    name: 'demo1',
    title: '本地子应用',
    url: '//localhost:9898/App1/home00',
  },
]

/**
 * 微服务配置生产环境
 */
export const ProMicroAppConfig: MicroAppConfig[] = [
  {
    name: 'demo1',
    title: '本地子应用',
    url: '//192.168.10.99:8888/demo1/',
  },
]
